﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace NJL.Web.Visitor2
{
    public partial class Default :BasePage
    {
        NJL.BLL.NJL_PERSON bllPerson = new BLL.NJL_PERSON();
        NJL.BLL.NJL_NEWS_COMMENT bllNewsComment = new BLL.NJL_NEWS_COMMENT();
        private readonly NJL.BLL.NJL_MYFRIEND bllMyFriend = new BLL.NJL_MYFRIEND();
        protected NJL.Model.NJL_PERSON modelPerson;
        int pageSize = 20;
        protected void Page_Load(object sender, EventArgs e)
        {
            modelPerson = bllPerson.GetModelByUserId(Request.QueryString["uid"]);
            DataSet ds = bllMyFriend.GetListInNews(pageSize, 1, "(NJL_MYFRIEND.NJL_USER_ID='"+Request["uid"]+"' or NJL_NEWS.NJL_PERSON_ID='"+UserId+"')");
            rptNews.DataSource = ds;
            InitializeComponent();
            rptNews.DataBind();
            ds = bllMyFriend.GetListInNews("NJL_MYFRIEND.NJL_USER_ID='" + Request["uid"] + "' or NJL_NEWS.NJL_PERSON_ID='"+UserId+"'");
            if (ds.Tables[0].Rows.Count <= pageSize)
            {
                moreArticle.Visible = false;
            }
        }
        //注册事件
        void InitializeComponent()
        {
            this.rptNews.ItemDataBound += new RepeaterItemEventHandler(this.rptNews_ItemDataBound);

        }
        protected void rptNews_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView drv = (DataRowView)e.Item.DataItem;
                string newsId = drv["ID3"].ToString();
                Repeater rptNewsComment = (Repeater)e.Item.FindControl("rptNewsComment");
                DataSet ds = bllNewsComment.GetListInUser(1, "a.NJL_NEWS_ID='" + newsId + "'", "a.CREATE_DATE_TIME desc");
                rptNewsComment.DataSource = ds;
                rptNewsComment.DataBind();
                Literal ltlCommentNum = e.Item.FindControl("ltlCommentNum") as Literal;
                ds = bllNewsComment.GetList("NJL_NEWS_ID='" + newsId + "'");
                ltlCommentNum.Text = ds.Tables[0].Rows.Count.ToString();
            }
        }

    
    }
}